﻿using PermissionManager.Attributes;
using PermissionManager.BLL;
using PermissionManager.Model;
using PermissionsManager.Models;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace PermissionsManager.Controllers
{
    public class SystemController : Controller
    {
        private LogsService bll = new LogsService();
        private MenuFunctionService bll2 = new MenuFunctionService();
        private Opretation opretation = new Opretation();
        // GET: System
        public ActionResult MenuSection()
        {
            return View();
        }
        public ActionResult SystemLogs()
        {
            return View();
        }

        public ActionResult MenuFunction()
        {
            return View();
        }

        [Describe("查看日志")]
        public JsonResult QueryLogsAll(int page,int limit)
        {
            int count =0;
            List<LogsBase> logs = bll.QueryLogsAll();
            GetJsonToTable<LogsBase> getJson = new GetJsonToTable<LogsBase>()
            {
                msg = "",
                code = 0,
                count = bll.GetCount(a=>true,out count),
                data = logs.Skip((page - 1) * limit).Take(limit).ToList()
            };
            return Json(getJson,JsonRequestBehavior.AllowGet);

        }

        public JsonResult QueryFunctionAll(int page, int limit)
        {
            int count = 0;
            List<FunctionBase> logs = bll2.Query();
            GetJsonToTable<FunctionBase> getJson = new GetJsonToTable<FunctionBase>()
            {
                msg = "",
                code = 0,
                count = bll.GetCount(a => true, out count),
                data = logs.Skip((page - 1) * limit).Take(limit).ToList()
            };
            return Json(getJson, JsonRequestBehavior.AllowGet);
        }

        public JsonResult DeleteFunction(int id)
        {
            opretation.Success = bll2.DeleteFunction(id);
            return Json(opretation);
        }


    }
}